CSharpTest.Net
CommitTransaction Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.BPlusTree Assembly > CSharpTest.Net.Collections Namespace > TransactionLog<TKey,TValue> Class : CommitTransaction Method

token

Glossary Item Box

Commits the provided transaction

Syntax

Visual Basic (Declaration) 
Public Sub CommitTransaction( _
   ByRef token As TransactionToken _
) 
C# 
public void CommitTransaction( 
   ref TransactionToken token
)

Parameters

token

Example

BPlusTree/BPlusTree.Test/TestTransactionLog.cs

C#Copy Code
using (TempFile tmp = new TempFile())
{
    using (var log = new TransactionLog<int, string>(Options(tmp)))
    {
        var token = log.BeginTransaction();
        log.AddValue(ref token, 1, Guid.NewGuid().ToString());
        log.CommitTransaction(ref token);
        var test = new Dictionary<int, string>();
        long offset = 0;
        log.ReplayLog(test, ref offset);
        Assert.AreEqual(1, test.Count);
    }
    byte[] bytes = tmp.ReadAllBytes();

    var TestVariants =
        new Converter<KeyValuePair<int, byte[]>, byte[]>[]
            {
                kv => { kv.Value[kv.Key] ^= 0xff; return kv.Value; },
                kv => { kv.Value[kv.Key] = 0xff; return kv.Value; },
                kv => { byte[] b = kv.Value; Array.Resize(ref b, kv.Key); return b; },
            };

    for (int corruptionIx = 0; corruptionIx < bytes.Length; corruptionIx++)
    {
        foreach (var testcase in TestVariants)
        {
            byte[] corrupt = testcase(new KeyValuePair<int, byte[]>(corruptionIx, (byte[]) bytes.Clone()));
            tmp.WriteAllBytes(corrupt);

            using (var log = new TransactionLog<int, string>(Options(tmp)))
            {
                var test = new Dictionary<int, string>();
                log.ReplayLog(test);
                Assert.AreEqual(0, test.Count);
            }
            Assert.IsFalse(File.Exists(tmp.TempPath));
        }
    }
}
VB.NETCopy Code
Using tmp As New TempFile()
            Using log As var = New TransactionLog(Of Integer, String)(Options(tmp))
                Dim token As var = log.BeginTransaction()
                log.AddValue(token, 1, Guid.NewGuid().ToString())
                log.CommitTransaction(token)
                Dim test As var = New Dictionary(Of Integer, String)()
                Dim offset As Long = 0
                log.ReplayLog(test, offset)
                Assert.AreEqual(1, test.Count)
            End Using
            Dim bytes As Byte() = tmp.ReadAllBytes()

            Dim TestVariants As var = New Converter(Of KeyValuePair(Of Integer, Byte()), Byte())() {Function(kv) 
            kv.Value(kv.Key) = kv.Value(kv.Key) Xor &Hff
            Return kv.Value

End Function, Function(kv) 
            kv.Value(kv.Key) = &Hff
            Return kv.Value

End Function, Function(kv) 
            Dim b As Byte() = kv.Value
            Array.Resize(b, kv.Key)
            Return b

End Function}

            Dim corruptionIx As Integer = 0
            While corruptionIx < bytes.Length
                For Each testcase As var In TestVariants
                    Dim corrupt As Byte() = testcase(New KeyValuePair(Of Integer, Byte())(corruptionIx, DirectCast(bytes.Clone(), Byte())))
                    tmp.WriteAllBytes(corrupt)

                    Using log As var = New TransactionLog(Of Integer, String)(Options(tmp))
                        Dim test As var = New Dictionary(Of Integer, String)()
                        log.ReplayLog(test)
                        Assert.AreEqual(0, test.Count)
                    End Using
                    Assert.IsFalse(File.Exists(tmp.TempPath))
                Next
                System.Math.Max(System.Threading.Interlocked.Increment(corruptionIx),corruptionIx - 1)
            End While
        End Using

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys